package com.rookie.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author rookie
 * @date 2022/5/7 14:27
 */
public class Observable {

    private List<Observer> observers = new ArrayList<>();

    //订阅
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    //取消订阅
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    //通知
    public void notifyObservers(String event) {
        for (Observer observer : observers) {
            //改变
            observer.update(event);
        }
    }

}
